﻿using System;
using System.Collections.Generic;

using EHSubmit.Model;
using EHSubmit.Logic.Services;

namespace EHSubmit.Logic.Relationship
{

    /// <summary>
    /// 管理学生、教师、课程关系
    /// </summary>
    public class RelationshipManagerImpl : IRelationshipManager
    {
        public RelationshipManagerImpl()
        {
        }


        /// <summary>
        /// 根据学生ID，返回对该学生所布置的作业
        /// </summary>
        /// <param name="sid">学生ID</param>
        /// <returns>作业信息</returns>
        public IList<Goal> GetGoalsOfStudent(string sid)
        {
            
            IList<Course> courses = null;
            IList<Goal> goals = null;
            IList<Homework> works = null;

            // 获得此学生所有已提交作业的集合
            HomeworkManager workManager = new HomeworkManager();
            works = workManager.ListFromStudent(sid);

            // 从远程获得选课信息
            IRemoteDataProxy proxy = RemoteProxyFactory.GetDataProxy();
            courses = proxy.GetCoursesOfStudent(sid);

            if (courses != null)
            {
                //查询布置给该生作业任务
                GoalManager goalManager = new GoalManager();
                goals = goalManager.GetGoalsOfCourses(courses, works);
            }
            return goals;
        }


        /// <summary>
        /// 根据教师ID,返回该教师所授的课
        /// </summary>
        /// <param name="tid">教师ID</param>
        /// <returns>授课信息</returns>
        public IList<Course> GetCoursesOfTeacher(string tid)
        {
            IList<Course> courses = null;
            IRemoteDataProxy proxy = RemoteProxyFactory.GetDataProxy();
            courses = proxy.GetCoursesOfTeacher(tid);

            return courses;
        }

        /// <summary>
        /// 根据教师ID,返回该教师所授的课程类型
        /// </summary>
        /// <param name="tid">教师ID</param>
        /// <returns>授课信息,不是课程班级</returns>
        public IList<BaseCourse> GetBaseCourseOfTeacher(string tid)
        {
            IList<BaseCourse> baseCourses = null;
            IRemoteDataProxy proxy = RemoteProxyFactory.GetDataProxy();
            baseCourses = proxy.GetBaseCourseOfTeacher(tid);

            return baseCourses;
        }

        /// <summary>
        /// 根据课程ID,返回选了该课的学生信息
        /// </summary>
        /// <param name="cid">课程ID</param>
        /// <returns>学生信息</returns>
        public IList<User> GetStudentsOfCourse(string cid)
        {
            IList<User> students = null;
            
            IRemoteDataProxy proxy = RemoteProxyFactory.GetDataProxy();
            students = proxy.GetStudentsOfCourse(cid);

            return students;
        }

        /// <summary>
        /// 根据学生ID，返回该学生的选课信息
        /// </summary>
        /// <param name="sid">学生ID</param>
        /// <returns>选课信息</returns>
        public IList<Course> GetCoursesOfStudent(string sid)
        {
            IList<Course> courses = null;

            IRemoteDataProxy proxy = RemoteProxyFactory.GetDataProxy();
            courses = proxy.GetCoursesOfStudent(sid);

            return courses;
        }
    }
}